{include file="public/base" /}
{block name="main"}
<style>
    .file {
        position: relative;
        display: inline-block;
        background: #D0EEFF;
        border: 1px solid #99D3F5;
        border-radius: 4px;
        padding: 4px 12px;
        overflow: hidden;
        color: #1E88C7;
        text-decoration: none;
        text-indent: 0;
        line-height: 20px;
    }

    .file input {
        position: absolute;
        font-size: 100px;
        right: 0;
        top: 0;
        opacity: 0;
    }

    .file:hover {
        background: #AADFFD;
        border-color: #78C3F3;
        color: #004974;
        text-decoration: none;
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="get" action="javascript:;" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">开团标题</label>
                            <div class="col-sm-10">
                                <input type="text" name="title" class="form-control" value="{$goodsInfo['title']}" required>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"  id="kait">
                            <label class="col-sm-2 control-label">参团商品</label>
                            <div class="col-sm-10">
                                <ul style="display: block">
                                    {volist name="goods" id="val"}
                                    <li style="float:left;width:200px;"><input type="checkbox" name="lid[]" value="{$val.id}">{$val.goods}</li>
                                    {/volist}
                                </ul>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">社区</label>
                            <div class="col-sm-10">
                                <ul style="display: block">
                                    {foreach name="estate" id="value"}
                                    <li style="float:left;width:200px;"><input type="checkbox" name="eid[]" value="{$value['id']}">{$value['estate']}</li>
                                    {/foreach}
                                </ul>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">开始时间</label>
                            <div class="col-sm-10">
                                <input type="datetime-local" name="start_time" class="form-control" value="<?php echo date('Y-m-d',$goodsInfo["start_time"])."T".date('H:i:s',$goodsInfo["start_time"]);?>" required>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">结束时间</label>
                            <div class="col-sm-10">
                                <input type="datetime-local" name="end_time" class="form-control" value="<?php echo date('Y-m-d',$goodsInfo["end_time"])."T".date('H:i:s',$goodsInfo["end_time"]);?>" required>
                            </div>
                        </div>
                      	 <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">预计到货时间</label>
                            <div class="col-sm-10">
                                <ul style="display: block">
                                    <input type="text" value="{$goodsInfo['arrival']}"  name="arrival"  class="form-control" required>
                                </ul>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <input type="hidden" name="id" value="{$goodsInfo['id']|default=0}">
                                <button class="btn btn-primary" type="submit" onclick="edit()">保存内容</button>
                                <!--<button class="btn btn-white" type="submit">取消</button>-->
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="javascript"}
<script src="ADMIN_JS/content.min.js?v=1.0.0"></script>
<script src="ADMIN_JS/plugins/iCheck/icheck.min.js"></script>
<script>
  	var shuz=[];
    var shust='';
      $('#kait [type = checkbox]').click(function(e){
        if($.inArray(e.target.value,shuz) == -1){
              shuz.push(e.target.value)
           }else{
             shuz.splice($.inArray(e.target.value,shuz),1);
           }
      })
    window.onload=function(){
        // $("[name='eid'] [value='{$goodsInfo[\"eid\"]}']").attr('selected',true);var power_id = a.substring(1);
        var power_ids = '{$goodsInfo.gid}';
        var eids = '{$goodsInfo.eid}';
        var power_id = power_ids.substring(1);
        power_id = power_id.substr(0,power_id.length-1);
        var eid = eids.substring(1);
        eid = eid.substr(0,eid.length-1);
        power_id = power_id.split(",");
        eid = eid.split(",");
        // console.log(power_id);
        var i=0;
        for(i=0;i<eid.length;i++){
            $("[type='checkbox'][name='eid[]'][value="+eid[i]+"]").attr('checked',true);
        }
        for(i=0;i<power_id.length;i++){
            $("[type='checkbox'][name='lid[]'][value="+power_id[i]+"]").attr('checked',true);
        }
      	 //追加
      $.each(power_id,function(i,t){
      	shuz.push(power_id[i]);
      })
    }
    function edit()
    {
        var title = $("[name='title']").val();
        var start_time = $("[name='start_time']").val();
        var end_time = $("[name='end_time']").val();
      	var arrival= $("[name='arrival']").val();
        var obj = document.getElementsByName("eid[]");
        var check_vale = [];
        for(k in obj){
            if(obj[k].checked)
                check_vale.push(obj[k].value);
        }
        if(title == ''){
            layer.msg('标题不能为空',{icon:5,time:1500});
            return false;
        }
        if(shuz == ''){
            layer.msg('参团商品不能为空',{icon:5,time:1500});
            return false;
        }
        if(check_vale == ''){
            layer.msg('参团社区不能为空',{icon:5,time:1500});
            return false;
        }
      	if(arrival == ''){
            layer.msg('预计到货时间不能为空',{icon:5,time:1500});
            return false;
        }
        var formData = new FormData();
        formData.append("title", title);
        formData.append("eid", check_vale);
        formData.append("start_time", start_time);
        formData.append("end_time", end_time);
        formData.append("gid", shuz);
      	formData.append("arrival", arrival);
        var id = $("[name='id']").val();
        if(id!=0){
            var url = '{:url("goods/groupEdit")}';
            formData.append("id", id);
        }else{
            var url = '{:url("goods/groupAdd")}';
        }
        var loading = layer.msg('正在提交数据，请稍后...', {icon: 16,time:6000});
        $.ajax({
            type:'post',
            url:url,
            data:formData,
            contentType: false,
            processData: false,
            success:function(data){
                layer.close(loading);
                if(data.code==1){
                    layer.msg(data.msg,{icon:6,time:1500});
                    setTimeout(function(){window.parent.location.reload();},1000);
                }else{
                    layer.msg(data.msg,{icon:5,time:1500});
                }
            }
        })
    }

</script>
{/block}